<template>
    <div class='department'>
        <div class="container">
            <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" class="search-con">
                <!-- <el-col :span="24" style="margin-bottom: 20px;"> -->
                    <el-form-item>
                        <el-button size="mini" v-for="item, index in btnList" :key="index" @click="changeTab(item, index)"
                            :type="curLine == index ? 'primary' : 'default'">
                            {{ item.dictLabel }}</el-button>
                    </el-form-item>
                <!-- </el-col> -->
                <!-- <el-form-item label="部门名称" prop="key">
                    <el-input v-model="queryParams.key" placeholder="请输入" clearable size="small" />
                </el-form-item> -->
                <!-- <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item> -->
            </el-form>
            <el-row :gutter="10" class="mb8">
                <!-- <el-col :span="22">
                    <el-button type="primary" icon="el-icon-plus" size="mini" @click="title='新增';handleShow='add'" v-hasPermi="['user:depart:add']">
                        新增</el-button>
                </el-col> -->
                <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <el-table border v-loading="loading" :data="tableList" ref="tableList" v-tableHeight :height="tableList.length>0?'900px':'120px'">
                <el-table-column label="编号" align="center" prop="id" />
                <el-table-column label="用户名" align="center" prop="name" />
                <el-table-column label="默认会员等级" align="center" prop="name" />
                <el-table-column label="注册时间" align="center" prop="name" />
                <el-table-column label="备注" align="center" prop="name" />
                <el-table-column label="状态" align="center" prop="status">
                    <template slot-scope="scope">
                        <span>
                            {{selectDictLabel(btnList, scope.row.status)}}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                        <!-- <el-button v-if="scope.row.status==0" size="mini" type="text" @click="handleAble(scope.row)" v-hasPermi="['user:depart:stop']">不通过
                        </el-button> v-if="scope.row.status==1" statusList-->
                        <el-button  size="mini" type="text" @click="handleAble(scope.row)" v-hasPermi="['user:depart:start']">审批
                        </el-button>
                        <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['user:depart:del']">
                            删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="pageCount>0" :pageCount="pageCount" :page.sync="queryParams.page" :limit.sync="queryParams.limit" @pagination="getList" />
        </div>
        <el-dialog :title="title" visible v-if="handleShow" @close="close()" width="400px" append-to-body :close-on-click-modal="false">
            <el-form ref="form" :model="form" :rules="rules" label-width="80px" v-loading="formLoading">
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="审核结果" prop="apply_state">
                            <el-select v-model="form.apply_state" placeholder="请选择" clearable size="small" filterable>
                                <el-option v-for="dict in aplStateList" :key="dict.dictValue" :label="dict.dictLabel" :value="dict.dictValue" />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="备注" prop="notes">
                            <el-input v-model="form.notes" placeholder="不通过请输入备注" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="close()">取 消</el-button>
                <el-button type="primary" @click="submit" :disabled="formLoading">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
import { getApplyLists, examApply } from "@/api/distribution/distribution.js"

import { departStatus } from "@/api/dictionary"

import throttle from 'lodash.throttle'
export default {
    name: 'department',
    props: {

    },
    data() {
        return {
            showSearch: true,
            loading: false,
            pageCount: 0,
            total: 0,
            queryParams: {
                page: 1,
                limit: 20,
                apply_state:'',
            },
            tableList: [{id:1,name:"张胜男",status:0}],
            statusList: departStatus,
            handleShow: "",
            formLoading: false,
            form: {
                record_id: null,
                apply_state: null,
                notes:'',
            },
            rules: {
                apply_state: [{ required: true, message: '请选择审批结果', trigger: 'blur' }],
            },
            title: "",
            curLine: 0,
            btnList: [
                {
                    dictLabel: '全部',
                    dictValue: ''
                },
                {
                    dictLabel: '审核中',
                    dictValue: 0
                },
                {
                    dictLabel: '审核通过',
                    dictValue: 1
                },
                {
                    dictLabel: '审核拒绝',
                    dictValue: -1
                }
            ],
            aplStateList: [
                {
                    dictLabel: '审核通过',
                    dictValue: 1
                },
                {
                    dictLabel: '审核拒绝',
                    dictValue: 0
                }
            ],
        }
    },
    created() {
        // this.getList()
    },
    methods: {
        getList() {
            this.loading = true;
            getApplyLists(this.queryParams).then(res => {
                this.tableList = res.data.lists;
                this.pageCount = res.data.pageCount;
                this.loading = false;
            });
        },
        changeTab(item, index) {
            this.curLine = index
            this.queryParams.apply_state = item.dictValue
            this.getList()
        },
        handleQuery() {
            this.queryParams.page = 1;
            this.getList();
        },
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },
        close() {
            this.form = {}
            this.handleShow = ""
        },
        // handleAble(row) {
        //     let label = row.status == 0 ? '停用' : '启用';
        //     this.$confirm(`是否将“${row.name}”${label}?`, "警告", {
        //         confirmButtonText: "确定",
        //         cancelButtonText: "取消",
        //         type: "warning"
        //     }).then(function () {
        //         return setSectorStatus({ sector_id: row.id });
        //     }).then(() => {
        //         this.getList();
        //         this.msgSuccess(`${label}成功`);
        //     })
        // },
        // handleDelete(row) {
        //     this.$confirm('是否确认删除' + '"' + row.name + '"' + '?', "警告", {
        //         confirmButtonText: "确定",
        //         cancelButtonText: "取消",
        //         type: "warning"
        //     }).then(function () {
        //         return delSector({ sector_id: row.id });
        //     }).then(() => {
        //         this.getList();
        //         this.msgSuccess("删除成功");
        //     })
        // },
        handleAble(row){
            this.handleShow = 'edit';
            this.title = '审批填写';
            this.form.record_id = row.id
        },
        submit: throttle(function () {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    this.formLoading = true;
                    // this.form.sector_id = this.form.id ? this.form.id : null
                    examApply(this.form).then(res => {
                        this.msgSuccess("操作成功！");
                        this.close()
                        this.formLoading = false;
                        this.getList();
                    }).catch(() => {
                        this.formLoading = false;
                    })
                }
            })
        }, 1000, { trailing: false }),
    }
}
</script>

<style lang='scss' scoped>
</style>
